import libtcodpy as libtcod

class NPCStats(object):
	def __init__(self):
		
		self.str = libtcod.random_get_int(0, 3, 10)
		self.per = libtcod.random_get_int(0, 3, 10)
		self.end = libtcod.random_get_int(0, 3, 10)
		self.chr = libtcod.random_get_int(0, 3, 10)
		self.int = libtcod.random_get_int(0, 3, 10)
		self.agi = libtcod.random_get_int(0, 3, 10)
		self.luk = libtcod.random_get_int(0, 3, 10)



class BaseCombat(object):
	def __init__(self):
		pass
		
	def get_damage(self):
		return 1
	
class ActorCombat(BaseCombat):
	def __init__(self):
		self.stats = NPCStats()			
		#reset player hp
		pass
		
	def update_actor(self):
		
		self.owner.hp = self.get_max_hp()	
		self.owner.stamina = self.get_max_stamina()

		
	def get_damage(self):
		return self.stats.str + self.get_equip_bonis("damage")
		
	def get_stun_chance(self):
		return self.stats.str + self.get_equip_bonis("stun_chance")
		
	def get_stun_duration(self):
		return 10 - 5*(float(self.stats.agi)/10)	#stun for 5-10 turns
		
	def get_fov(self):		
		fov = int((5 + self.stats.per)*1.2)
		if self.owner.em.services["sk_time"].is_night():
			fov = int( fov * 0.7 )
		return fov
		
	def get_max_hp(self):
		return 20 + 4*self.stats.end
		
	def get_damage_type(self):
		
		if self.owner.container and hasattr(self.owner.container,"equipment"):
			for weapon in self.owner.container.equipment:
				dmg_type =  weapon.get_effect("damage_type")
				if dmg_type:
					return weapon.get_effect("damage_type")

		return "dmg_generic"
		
	def get_equip_bonis(self, effect_id):
		if not hasattr(self.owner.container,"equipment"):
			return 0
		
		bonus = 0
		for weapon in self.owner.container.equipment:
			if weapon.get_effect(effect_id):
				bonus += weapon.get_effect(effect_id)
			
		return bonus	
		
	def get_defence(self):
		return self.get_equip_bonis("defence")
		
	#-------------------------------------------------------------------
	
	def get_max_stamina(self):
		return 200 + 5 * self.stats.end
	
class PlayerCombat(ActorCombat):
	def __init__(self):
		super(PlayerCombat,self).__init__()
	
	#def get_damage(self):
	#	return self.stats.str + self.get_equip_bonis("damage")
		
	#def get_stun_chance(self):
	#	return self.stats.str + self.get_equip_bonis("stun_chance")
	
	'''def get_damage_type(self):
		for weapon in self.owner.container.equipment:
			if weapon.get_effect("damage_type"):
				return weapon.get_effect("damage_type")'''
